/**
 * 
 */
package com.cr.backbone.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.apache.taglibs.standard.tag.common.core.OutSupport;
import org.aspectj.util.FileUtil;

/**
 * @project RaedNote
 * @version 1.0
 * @company 
 * @fileType NetWorkLisnter NetWorkLisnter.java
 * @author huxh
 * @date 2012-7-16
 */
/**
 * 
 * @author huxh
 * @date 2012-7-16 
 */
public class NetWorkLisnter {
	
	/**
	 * get http connection
	 * 
	 * @param httpUrl
	 * @return
	 * @author huxh
	 * @date 2012-7-16
	 */
	public Boolean getHttpURLConnectionisWork(String httpUrl){
		Boolean work=false;
		try {
			URL url = new URL(httpUrl);
			HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
			urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0");
			urlConnection.setFollowRedirects(true);
			urlConnection.connect();
			System.out.println(urlConnection.getResponseCode());
			
			
			InputStream in = urlConnection.getInputStream();
			File toDir=new File("d://a.html");
			OutputStream out = new FileOutputStream(toDir);
			FileUtil.copyStream(in, out);
			
			System.out.println(httpUrl+" connect success");
//			byte[] buffer = new byte[this.htmlCodeSize];
//			in.read(buffer);
//			htmlCode = new String(buffer);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		return work;
	}
	
	
	public static void main(String[] args) {
		NetWorkLisnter netWorkLisnter=new NetWorkLisnter();
//		String httpUrl="http://www.baidu.com";
//		String httpUrl="http://www.licaiedu.com/licaieduweb/index.jspa";
		String httpUrl="http://afp.licaiedu.com/login.jspa";
//		String httpUrl="http://cfp.fpsbchina.org/fpscc/";
		netWorkLisnter.getHttpURLConnectionisWork(httpUrl);
	}

}
 